<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>论文列表</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
    <link rel="stylesheet" href="/style.css">
</head>
<body>
<div class="container">
    <!-- Sidebar -->
    <div class="sidebar">
        <div class="sidebar-header">
            <h2>系统</h2>
        </div>
        <ul class="sidebar-menu">
            <li><a href="/home">仪表盘</a></li>
            <li><a href="/papers">论文管理</a></li>
        </ul>
    </div>

    <!-- Main content -->
    <div class="main-content">
        <header class="header">
            <h1>论文管理</h1>
            <!-- 添加论文按钮 -->
            <button class="btn btn-primary" onclick="window.location.href='/papers/add'">添加新论文</button>

            <!-- 搜索框 -->
            <form action="/papers" method="GET" style="display:inline; float:right;">
                <input type="text" name="search" placeholder="搜索论文..." th:value="${search}">
                <button type="submit">搜索</button>
            </form>
        </header>

        <section class="papers-table">
            <table>
                <thead>
                <tr>
                    <th>标题</th>
                    <th>作者</th>
                    <th>发表日期</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="paper : ${papers}">
                    <td><a th:href="@{/papers/detail/{id}(id=${paper.id})}" th:text="${paper.title}"></a></td>
                    <td th:text="${paper.author}"></td>
                    <td th:text="${#dates.format(paper.pubdate, 'yyyy-MM-dd')}"></td>
                    <td>
                        <button class="btn btn-edit" th:onclick="|window.location.href='/papers/edit/' + [[${paper.id}]]|">编辑</button>
                        <form action="/papers/delete" method="POST" style="display:inline;" onsubmit="return confirmDelete();">
                            <input type="hidden" name="id" th:value="${paper.id}">
                            <button class="btn btn-delete" type="submit">删除</button>
                        </form>
                    </td>
                </tr>
                </tbody>
            </table>
        </section>
    </div>
</div>

<script>
    // 提示删除确认框
    function confirmDelete() {
        return confirm("确定要删除这篇论文吗？");
    }
</script>

</body>
</html>
